home *** CD-ROM | disk | FTP | other *** search
/ AI Game Programming Wisdom / AIGameProgrammingWisdom.iso / SourceCode / 06 General Architectures / 06 Rabin / robot.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2001-12-10  |  1.6 KB  |  68 lines

  1. /* Copyright (C) Steve Rabin, 2001. 
  2.  * All rights reserved worldwide.
  3.  *
  4.  * This software is provided "as is" without express or implied
  5.  * warranties. You may freely copy and compile this source into
  6.  * applications you distribute provided that the copyright text
  7.  * below is included in the resulting source code, for example:
  8.  * "Portions Copyright (C) Steve Rabin, 2001"
  9.  */
  10.  
  11. #include "robot.h"
  12. #include <string.h>
  13.  
  14.  
  15. //Add new states here
  16. enum States { STATE_Initialize,
  17.               STATE_Wander
  18. };
  19.  
  20.  
  21. //Note: The macro keywords can be highlighted by placing them in the file 
  22. //USERTYPE.DAT in the same directory as MSDEV.EXE
  23.  
  24. bool Robot::States( StateMachineEvent event, MSG_Object * msg, int state )
  25. {
  26. BeginStateMachine
  27.  
  28.     OnMsg( MSG_ChangeState ) //Default msg response (if not handled inside current state)
  29.         m_timer--;
  30.  
  31.     ///////////////////////////////////////////////////////////////
  32.     State( STATE_Initialize )
  33.         OnEnter
  34.             unsigned int paper = 8;
  35.             paper++;
  36.             m_timer = 0;
  37.             char test[256];
  38.             strcpy( test, statename );
  39.             SendDelayedMsg( 1.0f, MSG_Timeout, m_Owner->GetID() );
  40.             SendDelayedMsgToMe( 10.0f, MSG_ChangeState, SCOPE_TO_THIS_STATE );
  41.  
  42.         OnMsg( MSG_Timeout )
  43.             m_timer--;
  44.  
  45.         OnUpdate
  46.             m_timer++;
  47.             if( m_timer > 10 ) {
  48.                 SetState( STATE_Wander );
  49.             }
  50.             
  51.         OnExit
  52.             unsigned int joke = 5;
  53.             joke++;
  54.  
  55.     
  56.     ///////////////////////////////////////////////////////////////
  57.     State( STATE_Wander )
  58.  
  59.         OnMsg( MSG_ChangeState )
  60.             SetState( STATE_Initialize );
  61.     
  62.         OnUpdate
  63.             m_timer = 0;
  64.  
  65.  
  66. EndStateMachine
  67. }
  68.